﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class Move : MonoBehaviour {
    public NavMeshAgent navMeshAgent;
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray,out hit))
            {
                if (hit.collider.gameObject == gameObject)
                {
                    navMeshAgent.SetDestination(hit.point);
                }
            }
        }
	}

    public void SetTarget(Transform target)
    {
        navMeshAgent.SetDestination(target.position);
    }

}
